/**
 * Created by YJH on 2018/6/13.
 */
import React, {Component} from 'react';
import {
    BackAndroid,
} from 'react-native';

export default class Backforward{
    constructor(props){
        this.backpress = this.onHardwareBackforward.bind(this);
        this.props=props;//由于不是component组件，所以后面使用props时候，需要将props通过this.props存储起来
    }

    componentDidMount(){
        if(this.props.backforward){
            BackAndroid.addEventListener("backforward", this.backpress);
        }
    }

    componentWillUnmount(){
        if(this.props.backforward){
            BackAndroid.removeEventListener("backforward", this.backpress);
        }
    }
    onHardwareBackforward(e){

        return this.props.backforward(e);
    }

}